package com.gec.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gec.model.entity.SysBuild;
import com.gec.model.entity.SysComplaint;
import com.gec.system.service.SysBuildService;
import com.gec.system.service.SysCommunityService;
import com.gec.system.service.SysComplaintService;
import com.gec.system.service.SysHouseService;
import com.gec.system.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Wrapper;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

///admin/system/sysDashboard
@Api(tags = "数据管理控制器")
//登录注册控制器
@RestController
@RequestMapping("/admin/system/sysDashboard")
public class SysDashboardController {

    @Autowired
    private SysCommunityService sysCommunityService;

    @Autowired
    private SysBuildService sysBuildService;
    @Autowired
    private SysHouseService sysHouseService;

    @ApiOperation("查询所有小区的数量")
    @GetMapping("/selectCommunityCount")
    public Result selectCommunityCount(){

        int count = this.sysCommunityService.count();
        return Result.ok(count);
    }
    @ApiOperation("查询楼栋的数量")
    @GetMapping("/selectBuildCount")
    public Result selectBuildCount(){

        int count = this.sysBuildService.count();
        return Result.ok(count);
    }
    @ApiOperation("查询房屋的数量")
    @GetMapping("/selectHouseCount")
    public Result selectHouseCount(){

        int count = this.sysBuildService.selectHouseCount();
        return Result.ok(count);
    }
    @ApiOperation("查询人口的数量")
    @GetMapping("/selectPeopleCount")
    public Result selectPeopleCount(){

        int count= this.sysBuildService.selectPeopleCount();

        return Result.ok(count);
    }

    @ApiOperation("获取楼栋名字和人口")
    @GetMapping("/getBuildData")
    public Result getBuildData(){
//        Map<String,Integer> map=new HashMap<>();
//
//
        List<SysBuild> list2 = this.sysBuildService.list();
//        System.out.println(list);
//        for (SysBuild build : list) {
//            map.put(build.getName(), build.getTotalOwner());
//        }
        List<Map<String,Object>> list = new ArrayList<>();
        for (SysBuild build :list2){
          Map<String,Object>map =   new HashMap<String,Object>();
          map.put("name", build.getName());
          map.put("value", build.getTotalOwner());
            list.add(map);
        }
        return Result.ok(list);
    }
}
